package top.liubaiblog.blog.mqlistener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import top.liubaiblog.blog.constant.RabbitConstants;
import top.liubaiblog.blog.message.EmailMessage;
import top.liubaiblog.blog.service.EmailService;

/**
 * @author 留白
 * @description
 */
@Slf4j
@Component
public class EmailRabbitListener {
    @Autowired
    private EmailService emailService;

    @RabbitListener(queues = RabbitConstants.EMAIL_QUEUE)
    public void emailListener(EmailMessage emailMessage) {
        try {
            emailService.send(emailMessage);
        } catch (Exception e) {
            log.error("邮件发送错误, ", e);
        }
    }
}
